package client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

import obj.MyObject;

public class StartClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MyObject myObject = new MyObject();
		Socket socket = null;
		ObjectInputStream inputStream = null;
		ObjectOutputStream outputStream = null;

		try {
			socket = new Socket("localhost", 4444);
			outputStream = new ObjectOutputStream(socket.getOutputStream());
			inputStream = new ObjectInputStream(socket.getInputStream());
			
			System.out.println("Connected to server!");

			//--------------------------------------------------------------------------------------------
			Scanner scanner = new Scanner(System.in);
			String str = null;
			while (scanner.hasNextLine()) {
				str = scanner.nextLine();
				myObject.setStr(str);
				outputStream.writeObject(myObject);
				if (str.equals("quit")) {
					break;
				}
				myObject = (MyObject) inputStream.readObject();
				myObject.doingSomething("Client");
			}

			scanner.close();
			//--------------------------------------------------------------------------------------------
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

}
